package com.atsmart.app.sql;

import com.atsmart.app.utils.StringUtil;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;

public class UserImsiSql {
	private SQLiteDatabase db = null;

	/**
	 * 打开数据库
	 */
	public void open(SqlHelper dh) {
		// dh = new SqlHelper(null, "atsmart", null,SqlHelper.getDBVersion());
		db = dh.getWritableDatabase();
	}

/*    <string name="user_imsi">Create TABLE if not exists user_imsi( [_id] integer PRIMARY KEY
   ASC AUTOINCREMENT, [userimsi] text(200));</string>	*/ 
	public synchronized void addAttribute(String at) {
		 
		String strSql = "insert or replace into user_imsi (userimsi) values(?);";
		try {
			SQLiteStatement stm = db.compileStatement(strSql);
			stm.bindString(1, StringUtil.isEmptyOrNull(at) ? "" : at);
			stm.execute();
			stm.clearBindings();
			stm.close();
		} catch (Exception e) {
			
			// will not happen
		}
	}

	public String getAttribute() {
		String sql = " select _id, userimsi from user_imsi";
		Cursor cursor = db.rawQuery(sql, null);
		String info = null;
		try {
			if (cursor != null && cursor.moveToFirst()) {
				 info = cursor.getString(1);
			}
		} catch (Exception e) {
			return null;
		} finally {
			cursor.close();
		}
		return info;
	}

	public void deleteAttribute() {
		db.execSQL("delete from user_imsi");
	}
}
